cj_editor.init_list = {};
cj_editor.cover_pic = "images/pic_loading.png";

cj_editor.autoMinHeight = function(){
	var win_height = $(window).height(),
	  head_height = $('.yinji_templates_PictureStory_head').outerHeight(true),
	  bottom_height = $('.yinji_templates_PictureStory_bottom').outerHeight(true),
	  mess_height = win_height - head_height - bottom_height,
	  odd_height = $("#mess_ul").outerHeight(true);
	if (mess_height > 0) {
		$('#mess_ul').css('minHeight', mess_height);
	}
	if ($('.yinji_templates_PictureStory_box').hasClass('PictureStory_view_box')) {
		document.getElementById('title').readOnly=true;
		$('#title').click(function() {
			$('#title').blur();
		});
	}else{
		$('.set_cover').css('display', 'block');
		$('.set_time').children('img').css('display', 'inline-block');
	}

	var cover_pic_width = $('.yinji_templates_PictureStory_box').width();
	var cover_pic_height = cover_pic_width / 1.6304;
	$('#cover_pic').css({'height':cover_pic_height});
}

cj_editor.text_clear = function(that){   //文本提示类信息清空事件（编辑状态） 默认：editor_default  已修改：editor_modify
	if (that.hasClass('editor_default')) {
		that.html('');
		that.removeClass('editor_default');
		that.addClass('editor_modify');
	}
	
	if (that.hasClass('editor_modify')) {

	};
}

cj_editor.add_new_pic = function(src){   //新建图片内容之后（编辑状态）
	var user_location = '';
	/*
	if(location_mess){
		user_location = '<div class="imformation"><div class="location"><img src="images/icon_location.png" class="icon_location"><i>' + location_mess + '</i></div></div>';
	}
	*/
	var html_text = '<li class="mess_pic add_newmess_animation"><div class="yinji_templates_PictureStory_tool animation_tool"><img src="images/btn_delete.png" id="delete" class="delete"><img src="images/btn_cut.png" id="cut" class="cut"></div><div class="inner_pic"><img src="' + src +'" class="user_pic"><div class="btn_move"><img src="images/btn_move.png" class="btn_move_up" id="btn_move_up"><img src="images/btn_move.png" class="btn_move_down" id="btn_move_down"></div></div>' + user_location + '<p class="text_editor editor_default"><img src="images/icon_edit.png"><i>添加图片注释</i></p></li>'
	var html_add_newmess = '<div class="add_newmess newmess_temp" id="add_newmess"><div class="btn_add"><img src="images/btn_add_newmess.png"></div><div class="add_newmess_select"><div class="add_pic"><img src="images/btn_add_pic.png"></div><div class="add_text"><img src="images/btn_add_text.png"></div></div></div>'
	var that_p = $('.add_newmess_select_cur');
	var index_p = that_p.index('.add_newmess');
	$('.add_newmess_select_cur').after(html_text);
	$('.add_newmess_animation').after(html_add_newmess);
	//cj_editor.li_minSize();   //按比例设置每段内容最小尺寸（编辑状态）
	cj_editor.text_editor();   //文本编辑事件（编辑状态）
	cj_editor.tool_delete();   //删除（编辑状态）
	cj_editor.img_tool_change();
	cj_editor.btn_move();   //移动用户内容功能（编辑状态）

	var new_text_focus = index_p;
	var scorll_height = $('.add_newmess_animation').offset().top;
	var win_height = $(window).height();
	var scorll_top = scorll_height - win_height * 0.2;
	cj_editor.add_newmess(new_text_focus);   //新建内容（编辑状态）
	$('html,body').stop(true).animate({scrollTop: scorll_top + 'px'}, 350);  //窗口定位
	that_p.removeClass('add_newmess_select_cur');

	$(".newmess_temp").addClass('add_newmess_select_cur');
	$(".add_newmess_select_cur").removeClass("newmess_temp");
}

/*
$('.js_title').blur(function() {
	var that = $('.js_title');
	var number = that.text().length;
	if (number == 0 && that.hasClass('title')) {   //用户标题 == 0 时（编辑状态）
		that.attr('contenteditable', 'false');
		that.text('输入故事标题');
		that.removeClass('editor_modify');
		that.addClass('editor_default');
	};
	if (number > 0 && that.hasClass('title') && that.hasClass('editor_modify')) {   //用户标题 > 0 时（编辑状态）
      var user_title = that.text();
      that.attr('contenteditable', 'false');
      that.html(user_title);
      that.removeClass('editor_default');
      that.addClass('editor_modify');
    };
});
*/

cj_editor.text_check = function(that,number,number_i){   //用户在文本区域键入内容（编辑状态）默认：editor_default  已修改：editor_modify
	/*
	if (number == 0 && that.hasClass('title')) {   //用户标题 == 0 时（编辑状态）
		that.attr('contenteditable', 'false');
		that.text('输入故事标题');
		that.removeClass('editor_modify');
		that.addClass('editor_default');
	};

	if (number > 0 && that.hasClass('title')) {   //用户标题 > 0 时（编辑状态）
		var user_title = that.text();
		that.html(user_title);
		that.removeClass('editor_default');
		that.addClass('editor_modify');
		that.attr('contenteditable', 'false');
	};
	*/

	if (number > 0 && number_i == 0) {   //用户内容 > 0 时（编辑状态）
		var user_text = that.html();
		that.attr('contenteditable', 'false');
		that.html(user_text);
		that.removeClass('editor_default');
		that.removeClass('text_editor_cur');
		that.parent('.mess_text').removeClass('add_newmess_animation');
		that.parent('.mess_pic').removeClass('add_newmess_animation');
		that.addClass('editor_modify');
	};

	if (number == 0 && number_i == 0 && that.parent().hasClass('mess_text')) {   //用户内容(文字) == 0 时（编辑状态）
		that.attr('contenteditable', 'false');
		that.html('<img src="images/icon_edit.png"><i>添加文字内容</i>');
		that.removeClass('editor_modify');
		that.removeClass('text_editor_cur');
		that.parent('.mess_text').removeClass('add_newmess_animation');
		that.parent('.mess_pic').removeClass('add_newmess_animation');
		that.addClass('editor_default');
	};

	if (number == 0 && number_i == 0 && that.parent().hasClass('mess_pic')) {   //用户内容(图片) == 0 时（编辑状态）
		that.attr('contenteditable', 'false');
		that.html('<img src="images/icon_edit.png"><i>添加图片注释</i>');
		that.removeClass('editor_modify');
		that.removeClass('text_editor_cur');
		that.parent('.mess_text').removeClass('add_newmess_animation');
		that.parent('.mess_pic').removeClass('add_newmess_animation');
		that.addClass('editor_default');
	};
}

cj_editor.add_newmess = function(new_text_focus){   //新建内容（编辑状态）
	$('.btn_add').children('img').unbind('click');
	$('.btn_add').children('img').bind('click',function(event){
		var that_img = $(this);
		var that = that_img.parent('.btn_add');

		cj_editor.add_newmess_run(that_img);

		$('ul li').eq(new_text_focus).removeClass('add_newmess_animation');
		if (that.hasClass('btn_close')) {
			that.addClass('btn_open');
			that.parent().addClass('add_ed');
			that.removeClass('btn_close');
			that.parent().removeClass('add_ing');
		}else{
			that.addClass('btn_close');
			that.parent().addClass('add_ing');
			that.parent().siblings('.add_ing').addClass('add_ed');
			that.parent().siblings('.add_ing').children('.btn_add').addClass('btn_open');
			that.parent().siblings('.add_ing').children('.btn_add').removeClass('btn_close');
			that.parent().siblings('.add_ing').removeClass('add_ing');
			that.removeClass('btn_open');
			that.parent().removeClass('add_ed');
		}
		cj_editor.add_newmess_text();   //新建文字内容（编辑状态）
		cj_editor.add_newmess_pic();   //新建图片内容（编辑状态）
	});
}

cj_editor.add_newmess_run = function(that_img){   //执行新增动画时的优化（编辑状态）
	var that = that_img.parent().parent('.add_newmess');
	var that_eq = that.index('ul .add_newmess');
	var hide_eq = that_eq + 2;
	cj_editor.scorll_close(hide_eq);
}

cj_editor.scorll_close = function(hide_eq){   //滚动事件触发，显示隐藏内容（编辑状态）
	var odd_height = $("#mess_ul").height(); //固定总高度(7月5日)
	$('#mess_ul').css('minHeight', odd_height);
	$('ul .add_newmess:gt(' + hide_eq + ')').css('display', 'none');
	$('ul li:gt(' + hide_eq + ')').css('display', 'none');
	$(window).unbind('scroll');
	$(window).bind('scroll',function(hide_eq){
		$('ul .add_newmess').css('display', 'block');
		$('ul li').css('display', 'block');
	});
}

cj_editor.add_newmess_text = function(){   //新建文字内容（编辑状态）
	$('.add_text').unbind('click');
	$('.add_text').bind('click',function(event){
		var that_pic = $(this);
		var that = that_pic.parent('.add_newmess_select');
		var that_p = that.parent('.add_newmess');
		var index_p = that_p.index('.add_newmess');
		var html_text = '<li class="mess_text add_newmess_animation"><div class="yinji_templates_PictureStory_tool animation_tool"><img src="images/btn_delete.png" id="delete" class="delete"></div><p class="text_editor editor_default"><img src="images/icon_edit.png"><i>添加文字内容</i></p><div class="btn_move"><img src="images/btn_move.png" class="btn_move_up" id="btn_move_up"><img src="images/btn_move.png" class="btn_move_down" id="btn_move_down"></div></li>';
		var html_add_newmess = '<div class="add_newmess" id="add_newmess"><div class="btn_add"><img src="images/btn_add_newmess.png"></div><div class="add_newmess_select"><div class="add_pic"><img src="images/btn_add_pic.png"></div><div class="add_text"><img src="images/btn_add_text.png"></div></div></div>'
		that.siblings('.btn_add').addClass('btn_open');
		that.parent().addClass('add_ed');
		that.siblings('.btn_add').removeClass('btn_close');
		that.parent().removeClass('add_ing');
		that.parent().after(html_text);
		$('.add_newmess_animation').after(html_add_newmess);

		//cj_editor.li_minSize();   //按比例设置每段内容最小尺寸（编辑状态）
		cj_editor.text_editor();   //文本编辑事件（编辑状态）
		cj_editor.tool_delete();   //删除（编辑状态）
		cj_editor.img_tool_change();
		cj_editor.btn_move();   //移动用户内容功能（编辑状态）

		var new_text_focus = index_p;
		var scorll_height = $('.add_newmess_animation').offset().top;
		var win_height = $(window).height();
		var scorll_top = scorll_height - win_height * 0.2;
		var that = $('.add_newmess_animation').children('.text_editor');

		cj_editor.add_newmess(new_text_focus);   //新建内容（编辑状态）
		$('html,body').stop(true).animate({scrollTop: scorll_top + 'px'}, 350);  //窗口定位
		/*
		clearTimeout(t);
		var t = setTimeout(function(){
		  var that = $('.add_newmess_animation').children('.text_editor');
		  that.click();  //模拟点击
		  that.focus();  //光标定位
		},600);
		*/
	});
}

cj_editor.text_editor_focus = function(that) {   //文本编辑区域得到焦点（编辑状态）
    var el = that;
    var that = el.parent().siblings('li').children('.text_editor_cur');
    var number = that.text().length;
    var number_i = that.children('i').text().length;
    cj_editor.text_check(that,number,number_i);
	cj_editor.text_editor_blur();
}

cj_editor.tool_delete = function(){   //删除按钮（编辑状态）
	$('.delete').unbind('click');
	$('.delete').bind('click',function(event){
		var height = document.documentElement.clientHeight,   //-------- 7月5日
			head_h = $('.yinji_templates_PictureStory_head').outerHeight(true),
			boom_h = $('.yinji_templates_PictureStory_bottom').outerHeight(true),
			min_h = height - head_h - boom_h;
		if (min_h > 0) {
			$('#mess_ul').css('minHeight', min_h);
		}else{
			$('#mess_ul').css('minHeight', 'auto');
		}

		var that_li = $(this).parent().parent('li'),
			index_li = that_li.index('ul li'),
			h_li = that_li.height();
		that_li.css('height', h_li);

		$('ul li').eq(index_li).removeClass('add_newmess_animation');
		$('ul li').eq(index_li).addClass('delete_usermess_animation');
		$('.add_newmess').eq(index_li + 1).addClass('delete_newmess_animation');
		clearInterval(t);
		var t= setTimeout(function(){
			$('ul li').eq(index_li).remove();
			$('.add_newmess').eq(index_li + 1).remove();
		},500)
	});
}

cj_editor.text_editor = function(that){   //文本编辑事件（编辑状态）
	$('.text_editor').unbind('click');
	$('.text_editor').bind('click',function(event){
		var that = $(this);
		that.attr('contenteditable', 'true');
		that.focus();
		that.addClass('text_editor_cur');
		cj_editor.text_clear(that);
		cj_editor.text_editor_focus(that);
	});
}

cj_editor.add_newmess_pic = function(){   //新建图片内容之前（编辑状态）
	$('.add_pic').unbind('click');
	$('.add_pic').bind('click',function(event){
		var that_pic = $(this);
		var that = that_pic.parent('.add_newmess_select');
		that.siblings('.btn_add').addClass('btn_open');
		that.parent().addClass('add_ed');
		that.siblings('.btn_add').removeClass('btn_close');
		that.parent().removeClass('add_ing');
		that.parent().addClass('add_newmess_select_cur');

		cj_editor.img_class = "user_image";
		var CardScalewidth = 0;
		var CardScaleheight = 0;
		if(cj_editor.isUsingAndroid){
			selectPic.selectPic(CardScalewidth,CardScaleheight);
		}else if(cj_editor.isUsingiOS){
			selectPic(CardScalewidth,CardScaleheight);
		}else{
			console.log("call picture");
		}
	});
}

//更新
cj_editor.text_editor_blur = function(){   //文本编辑区域失去焦点（编辑状态）
	var that = $('.text_editor_cur');
	that.unbind('keyup');
	that.bind('keyup', function(event) {
		var number = that.text().length;
		var number_i = that.children('i').text().length;
		var code_number = event.keyCode;
		if (that.parent().hasClass('mess_pic') && code_number==13) {
			  var text = that.text();
			  that.html(text);
			  that.blur();
		};
	});

	that.blur(function() {
		var number = that.text().length;
		var number_i = that.children('i').text().length;
		cj_editor.text_check(that,number,number_i);
	});




}

cj_editor.setDefaultStart = function(){
	var new_text_focus = 0;
	$('#mess_ul').prepend('<div class="add_newmess" id="add_newmess"><div class="btn_add"><img src="images/btn_add_newmess.png"></div><div class="add_newmess_select"><div class="add_pic"><img src="images/btn_add_pic.png"></div><div class="add_text"><img src="images/btn_add_text.png"></div></div></div>')
}

cj_editor.SeDefaultEnd = function(){
	//new
	//cj_editor.li_minSize();   //按比例设置每段内容最小尺寸（编辑状态）
	//new
	cj_editor.add_newmess();
	cj_editor.text_editor();   //文本编辑事件（编辑状态）
	cj_editor.tool_delete();   //删除（编辑状态）
	cj_editor.img_tool_change();
	cj_editor.btn_move();   //移动用户内容功能（编辑状态）
}

//初始化渲染列表
cj_editor.setInitList = function(data,user_location) {
	if(data != ""){
		var data_obj = data.split(',');
		if(user_location){
			var user_location_obj = user_location.split(',');
		}
		var loop = 0;
		var redata = {};
		cj_editor.cover_pic = data_obj[0];
		$.each(data_obj, function(index, content){ 
			if(user_location_obj && user_location_obj[index]){
				redata[loop] = {"text":"","type":"image","src":content,"location":user_location_obj[index]};
			}else{
				redata[loop] = {"text":"","type":"image","src":content};
			}
			loop++;
			redata[loop] = {"text":"","type":"text"};
			loop++;
		});
		loop--;
		cj_editor.init_list = redata;
	}
}


cj_editor.btn_move = function(){    //移动用户内容功能（编辑状态）
	$('.btn_move_up').unbind('click');
	$('.btn_move_up').bind('click',function(){    //btn_up!
		$('.add_newmess_animation').removeClass('add_newmess_animation');
		$('.animation_tool').removeClass('animation_tool');
		var that = $(this);
		if (that.parent().parent('.inner_pic').hasClass('inner_pic')) {
		  var li_parent = that.parent().parent('.inner_pic'),
			  li_this = li_parent.parent('li'),
			  this_index = li_this.index('ul li'),
			  li_prev =  $('#mess_ul').children('li').eq(this_index - 1),
			  this_height = parseInt(li_this.outerHeight(true)),
			  newmess_height = parseInt($('.add_newmess').outerHeight(true)),
			  this_Y = parseInt(li_this.offset().top - $('#mess_ul').offset().top),
			  this_X = parseInt(li_this.offset().left - $('#mess_ul').offset().left),
			  prev_Y = parseInt(li_prev.offset().top - $('#mess_ul').offset().top),
			  this_Top = prev_Y,
			  prev_Top = parseInt(prev_Y + this_height + newmess_height),
			  prev_Left = parseInt(li_prev.offset().left - $('#mess_ul').offset().left);
			cj_editor.btn_moving(li_this,li_prev,this_X,this_Y,prev_Y,this_Top,prev_Top,prev_Left);
		}else{
			var li_this = that.parent().parent('li'),
			this_index = li_this.index('ul li'),
			li_prev =  $('#mess_ul').children('li').eq(this_index - 1),
			this_height = parseInt(li_this.outerHeight(true)),
			newmess_height = parseInt($('.add_newmess').outerHeight(true)),
			this_Y = parseInt(li_this.offset().top - $('#mess_ul').offset().top),
			this_X = parseInt(li_this.offset().left - $('#mess_ul').offset().left),
			prev_Y = parseInt(li_prev.offset().top - $('#mess_ul').offset().top),
			this_Top = prev_Y,
			prev_Top = parseInt(prev_Y + this_height + newmess_height),
			prev_Left = parseInt(li_prev.offset().left - $('#mess_ul').offset().left);
			cj_editor.btn_moving(li_this,li_prev,this_X,this_Y,prev_Y,this_Top,prev_Top,prev_Left);
		}
	});

	$('.btn_move_down').unbind('click');
	$('.btn_move_down').bind('click',function(){    //btn_down!
		$('.add_newmess_animation').removeClass('add_newmess_animation');
		$('.animation_tool').removeClass('animation_tool');
		var that = $(this);
		if (that.parent().parent('.inner_pic').hasClass('inner_pic')) {
		  var li_parent = that.parent().parent('.inner_pic'),
			  li_this = li_parent.parent('li'),
			  this_index = li_this.index('ul li'),
			  li_prev =  $('#mess_ul').children('li').eq(this_index + 1),
			  this_height = parseInt(li_this.outerHeight(true)),
			  prev_height = parseInt(li_prev.outerHeight(true)),
			  newmess_height = parseInt($('.add_newmess').outerHeight(true)),
			  this_Y = parseInt(li_this.offset().top - $('#mess_ul').offset().top),
			  this_X = parseInt(li_this.offset().left - $('#mess_ul').offset().left),
			  prev_Y = parseInt(li_prev.offset().top - $('#mess_ul').offset().top),
			  this_Top = this_Y + prev_height + newmess_height,
			  prev_Top = this_Y,
			  prev_Left = parseInt(li_prev.offset().left - $('#mess_ul').offset().left);
		  cj_editor.btn_moving(li_this,li_prev,this_X,this_Y,prev_Y,this_Top,prev_Top,prev_Left);
		}else{
		  var li_this = that.parent().parent('li'),
			  this_index = li_this.index('ul li'),
			  li_prev =  $('#mess_ul').children('li').eq(this_index + 1),
			  this_height = parseInt(li_this.outerHeight(true)),
			  prev_height = parseInt(li_prev.outerHeight(true)),
			  newmess_height = parseInt($('.add_newmess').outerHeight(true)),
			  this_Y = parseInt(li_this.offset().top - $('#mess_ul').offset().top),
			  this_X = parseInt(li_this.offset().left - $('#mess_ul').offset().left),
			  prev_Y = parseInt(li_prev.offset().top - $('#mess_ul').offset().top),
			  this_Top = this_Y + prev_height + newmess_height,
			  prev_Top = this_Y,
			  prev_Left = parseInt(li_prev.offset().left - $('#mess_ul').offset().left);
		  cj_editor.btn_moving(li_this,li_prev,this_X,this_Y,prev_Y,this_Top,prev_Top,prev_Left);
		}
	});
}

cj_editor.btn_moving = function(li_this,li_prev,this_X,this_Y,prev_Y,this_Top,prev_Top,prev_Left){   //内容移动
	var this_clon = li_this.clone(true),
	  prev_clon = li_prev.clone(true);
	$('#mess_ul').append(this_clon);
	$('#mess_ul').append(prev_clon);
	li_this.addClass('li_move');
	this_clon.addClass('li_clon');
	this_clon.css({
	'-webkit-transform': 'translate3d(' + this_X + 'px, 0, 0)',
	'-moz-transform': 'translate3d(' + this_X + 'px, 0, 0)',
	'-ms-transform': 'translate3d(' + this_X + 'px, 0, 0)',
	'transform': 'translate3d(' + this_X + 'px, 0, 0)',
	'position': 'absolute',
	'top': this_Y + 'px'
	});
	this_clon.stop(true).animate({top: this_Top + 'px'}, 360);  //移动交互动画
	li_prev.addClass('li_move');
	prev_clon.addClass('li_clon');
	prev_clon.css({
	'-webkit-transform': 'translate3d(' + prev_Left + 'px, 0, 0)',
	'-moz-transform': 'translate3d(' + prev_Left + 'px, 0, 0)',
	'-ms-transform': 'translate3d(' + prev_Left + 'px, 0, 0)',
	'transform': 'translate3d(' + prev_Left + 'px, 0, 0)',
	'position': 'absolute',
	'top': prev_Y + 'px'
	});
	prev_clon.stop(true).animate({top: prev_Top + 'px'}, 360);  //移动交互动画

	clearTimeout(t);
	var t = setTimeout(function(){
	$('.li_clon').remove();
	var this_class = li_this.attr('class'),    //得到上下文所有结构，包括html、css、class
		prev_class = li_prev.attr('class'),
		this_style = li_this.attr('style'),
		prev_style = li_prev.attr('style'),
		this_text = this_clon.find('.text_editor').html(),
		prev_text = prev_clon.find('.text_editor').html(),
		this_clear = this_clon.find('.text_editor').html(''),
		prev_clear = prev_clon.find('.text_editor').html(''),
		this_html = this_clon.html(),
		prev_html = prev_clon.html();

	li_this.replaceWith('<li class="li_this ' + prev_class + '" style="' + prev_style + '">' + prev_html + '</li>');
	li_prev.replaceWith('<li class="li_prev ' + this_class + '" style="' + this_style + '">' + this_html + '</li>');
	$('.li_this').find('.text_editor').html(prev_text);
	$('.li_prev').find('.text_editor').html(this_text);
	$('.li_this').removeClass('li_move');
	$('.li_this').removeClass('li_this');
	$('.li_prev').removeClass('li_move');
	$('.li_prev').removeClass('li_prev');

	cj_editor.text_editor();   //文本编辑事件（编辑状态）
	cj_editor.tool_delete();   //删除（编辑状态）
	cj_editor.btn_move();   //移动用户内容功能（编辑状态）
	},361);   //清理移动动作
}


cj_editor.load_user_mess_text = function(mess){   //载入用户内容(文字类)
	var user_mess = mess;   //内容数据
	if(mess == ""){
		var html_text = '<li class="mess_text add_newmess_animation"><div class="yinji_templates_PictureStory_tool animation_tool"><img src="images/btn_delete.png" id="delete" class="delete"></div><p class="text_editor editor_default yinji_edit_text"><img src="images/icon_edit.png"><i>添加文字内容</i></p><div class="btn_move"><img src="images/btn_move.png" class="btn_move_up" id="btn_move_up"><img src="images/btn_move.png" class="btn_move_down" id="btn_move_down"></div></li>';
	}else{
		var html_text = '<li class="mess_text add_newmess_animation"><div class="yinji_templates_PictureStory_tool animation_tool"><img src="images/btn_delete.png" id="delete" class="delete"></div><p class="text_editor editor_modify yinji_edit_text yinji_sethtml_text"></p><div class="btn_move"><img src="images/btn_move.png" class="btn_move_up" id="btn_move_up"><img src="images/btn_move.png" class="btn_move_down" id="btn_move_down"></div></li>';
	}
	var html_add_newmess = '<div class="add_newmess" id="add_newmess"><div class="btn_add"><img src="images/btn_add_newmess.png"></div><div class="add_newmess_select"><div class="add_pic"><img src="images/btn_add_pic.png"></div><div class="add_text"><img src="images/btn_add_text.png"></div></div></div>';
	$('#mess_ul').append(html_text);
	$('.add_newmess_animation').after(html_add_newmess);
	if(mess != ""){
		$('.yinji_sethtml_text').append(mess);
		$('.yinji_sethtml_text').removeClass("yinji_sethtml_text");
	}
}

cj_editor.load_user_mess_pic = function(mess,src){   //载入用户内容(图片类)
	var user_mess = mess;   //文字内容数据
	var user_pic_src = src   //图片内容数据
	var user_location = '';
	/*
	if(location_mess){
		user_location = '<div class="imformation"><div class="location"><img src="images/icon_location.png" class="icon_location"><i>' + location_mess + '</i></div></div>';
	}
	*/
	if(mess == ""){
		var html_pic = '<li class="mess_pic add_newmess_animation"><div class="yinji_templates_PictureStory_tool animation_tool"><img src="images/btn_delete.png" id="delete" class="delete"><img src="images/btn_cut.png" id="cut" class="cut"></div><div class="inner_pic"><img src="' + user_pic_src +'" class="user_pic"><div class="btn_move"><img src="images/btn_move.png" class="btn_move_up" id="btn_move_up"><img src="images/btn_move.png" class="btn_move_down" id="btn_move_down"></div></div>' + user_location + '<p class="text_editor editor_default"><img src="images/icon_edit.png"><i>添加图片注释</i></p></li>';
	}else{
		var html_pic = '<li class="mess_pic add_newmess_animation"><div class="yinji_templates_PictureStory_tool animation_tool"><img src="images/btn_delete.png" id="delete" class="delete"><img src="images/btn_cut.png" id="cut" class="cut"></div><div class="inner_pic"><img src="' + user_pic_src +'" class="user_pic"><div class="btn_move"><img src="images/btn_move.png" class="btn_move_up" id="btn_move_up"><img src="images/btn_move.png" class="btn_move_down" id="btn_move_down"></div></div>' + user_location + '<p class="text_editor editor_modify yinji_sethtml_text"></p></li>';
	}
	var html_add_newmess = '<div class="add_newmess" id="add_newmess"><div class="btn_add"><img src="images/btn_add_newmess.png"></div><div class="add_newmess_select"><div class="add_pic"><img src="images/btn_add_pic.png"></div><div class="add_text"><img src="images/btn_add_text.png"></div></div></div>'
	$('#mess_ul').append(html_pic);
	$('.add_newmess_animation').after(html_add_newmess);  

	if(mess != ""){
		$('.yinji_sethtml_text').append(user_mess);
		$('.yinji_sethtml_text').removeClass("yinji_sethtml_text");
	}
}

cj_editor.check_view_style = function(){   //浏览&编辑状态间的细节样式处理（display）
	var win_height = $(window).height(),
	  head_height = $('.yinji_templates_PictureStory_head').outerHeight(true),
	  bottom_height = $('.yinji_templates_PictureStory_bottom').outerHeight(true),
	  mess_height = win_height - head_height - bottom_height,
	  odd_height = $("#mess_ul").outerHeight(true);
	if (mess_height > 0) {
		$('#mess_ul').css('minHeight', mess_height);
	};
	if ($('.yinji_templates_PictureStory_box').hasClass('PictureStory_view_box')) {
		document.getElementById('title').readOnly=true;
		$('#title').click(function() {
			$('#title').blur();
		});
	}else{
		$('.set_cover').css('display', 'block');
		$('.set_time').children('img').css('display', 'inline-block');
	}
}

cj_editor.init = function(data,usetype){
	cj_editor.adaptive_size(720,100);
	cj_editor.autoMinHeight();
	cj_editor.check_view_style();
	cj_editor.init_run(true,usetype);
	var showData = '';
	if(data == ""){
		showData = {"yinji_title":"","yinji_describe":"添加图片注释","yinji_templates_cover":{"type":"image","value":cj_editor.cover_pic,"attachment":"true"},"yinji_templates_datalist":{"type":"text","value":cj_editor.init_list,"attachment":"true"},"yinji_templates_date":"2017.01.01"};
		//showData = {"yinji_title":"拾起心情录","yinji_describe":"","yinji_templates_cover":{"type":"image","value":"images/1.jpg","attachment":"true"},"yinji_templates_datalist":{"type":"text","value":{"0":{"text":" 吹了好久的夜风，直到全身哆嗦时才抬腿回家。猛然发现，我在逃避。我不想回家，曾经我把这个家当成我的一切。而现在，内心里只有恐惧。其实有的东西，就是自作自受。既然懦弱接受新的生活，那你活该煎熬。明天二十了，就算明天谁也不知道。你不准哭，因为你早已麻木了！","type":"text"},"2":{"text":"日出","type":"image","src":"images/2.jpg"},"0":{"text":"看到跳舞的小朋友从大巴车上下来，突然明白我为什么不开心了。好想学东西奈与现实。那个大巴车在我心里是期盼的它像夜色的的巨人！","type":"text"},"3":{"text":"小船浆","type":"image","src":"images/3.jpg"}},"attachment":"true"},"yinji_templates_date":"2017.6.1"};
	}else{
		showData = JSON.parse(data);
	}
	cj_editor.setHTML(showData);
	if($.isFunction(cj_editor.title_editor)){
		cj_editor.title_editor();
	}
}
